package org.xqp.pay.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xqp.basic.exception.MyException;
import org.xqp.basic.util.JsonResult;
import org.xqp.pay.dto.AlipayNotifyDto;
import org.xqp.pay.service.IPayService;

//支付API
@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private IPayService payService;

    //支付申请
    @PostMapping("/applyPay/{orderNo}")
    public JsonResult applyPay(@PathVariable("orderNo")String orderNo){
        try {
            //请求支付申请 , 这个结果是一个HTML代码
            String htmlResult = payService.applyPay(orderNo);
            return JsonResult.me().setResultObj(htmlResult);
        }catch (MyException e){
            return JsonResult.me().setMsg(e.getMessage());
        }catch (Exception e){
            return JsonResult.me().setMsg("系统异常");
        }

    }

    //异步通知   http://65cji7.natappfree.cc/pay/notify
    //谁在调用？支付宝      返回给谁？支付宝?
//    @RequestMapping("/notify")
//    public String alipayNotify(AlipayNotifyDto dto){
//        return payService.alipayNotify(dto);
//    }





}
